package hu.stud.uszeged.inf.prf.prftrac.session.dao;

import hu.stud.uszeged.inf.prf.prftrac.entity.Milestone;
import hu.stud.uszeged.inf.prf.prftrac.entity.Ticket;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;

@Name("ticketDao")
public class TicketDao {

	@In
	private EntityManager entityManager;
	
	public List<Ticket> getTickets(Milestone milestone) {
		String queryString = "from Ticket t where t.milestone = :milf";
    	Query q = entityManager.createQuery(queryString);
    	q.setParameter("milf", milestone);
    	return (List<Ticket>)q.getResultList();
	}
	
	public Ticket getTicket(Long id) {
		String queryString = "from Ticket t where t.id = :id";
    	Query q = entityManager.createQuery(queryString);
    	q.setParameter("id", id);
    	return (Ticket)q.getSingleResult();
	}
}
